package jp.dev7.hongo2.service;

import java.util.List;

import jp.dev7.hongo2.meta.QuestionMeta;
import jp.dev7.hongo2.model.Question;

import org.slim3.datastore.Datastore;

import com.google.appengine.api.datastore.Key;

public class QuestionService {

    private QuestionMeta q = QuestionMeta.get();

    public List<Question> findAll() {
        return Datastore
            .query(Question.class)
            .sort(q.key.asc.getSort())
            .asList();
    }

    public void create(Question question) {
        Datastore.put(question);
    }

    public Question getOrNull(Key key) {
        return Datastore.getOrNull(Question.class, key);
    }

    public void update(Question question) {
        if (question.getKey() == null) {
            throw new IllegalArgumentException("key is null");
        }
        Datastore.put(question);
    }

}
